import dayjs from 'dayjs'
import { ref } from 'vue'

//element el-date-picker 快捷选项
export const rangeShortcuts = ref([
  {
    text: '今天',
    value: () => [dayjs()]
  },
  {
    text: '昨天',
    value: () => [dayjs().subtract(1, 'day')]
  },
  {
    text: '本周',
    value: () => [dayjs().startOf('week').add(1, 'days'), dayjs().endOf('week').add(1, 'days')]
  },
  {
    text: '上周',
    value: () => [
      dayjs().subtract(1, 'weeks').startOf('week').add(1, 'days'),
      dayjs().subtract(1, 'weeks').endOf('week').add(1, 'days')
    ]
  },
  {
    text: '本月',
    value: () => [dayjs().startOf('month'), dayjs().endOf('month')]
  },
  {
    text: '上月',
    value: () => [dayjs().subtract(1, 'months').startOf('month'), dayjs().subtract(1, 'months').endOf('month')]
  },
  {
    text: '过去5天',
    value: () => [dayjs().subtract(5, 'day'), dayjs()]
  },
  {
    text: '过去7天',
    value: () => [dayjs().subtract(7, 'day'), dayjs()]
  },
  {
    text: '过去14天',
    value: () => [dayjs().subtract(14, 'day'), dayjs()]
  },
  {
    text: '过去30天',
    value: () => [dayjs().subtract(30, 'day'), dayjs()]
  },
  {
    text: '过去60天',
    value: () => [dayjs().subtract(60, 'day'), dayjs()]
  },
  {
    text: '过去180天',
    value: () => [dayjs().subtract(180, 'day'), dayjs()]
  }
])

//element el-date-picker 快捷选项
export const shortcuts = ref([
  {
    text: '今天',
    value: () => [dayjs(), dayjs()]
  },
  {
    text: '近7天',
    value: () => [dayjs().subtract(7, 'day'), dayjs()]
  },

  {
    text: '近一个月',
    value: () => [dayjs().subtract(30, 'day'), dayjs()]
  },
  {
    text: '近三个月',
    value: () => [dayjs().subtract(90, 'day'), dayjs()]
  },
  {
    text: '近一年',
    value: () => [dayjs().subtract(1, 'year'), dayjs()]
  }
])

export const shortcut = [
  {
    text: '近七天',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    }
  },
  {
    text: '近一个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    }
  },
  {
    text: '近三个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 90)
      return [start, end]
    }
  },
  {
    text: '近一年',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 365)
      return [start, end]
    }
  }
]

export function dateTimeFormat(time?: string) {
  return time ? time.substring(0, 10) + ' ' + time.substring(11, 19) : ''
}
